package com.jiangyg.mall.member.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.member.dto.IntegrationChangeHistoryDTO;
import com.jiangyg.mall.member.service.IntegrationChangeHistoryService;
import com.jiangyg.mall.member.vo.IntegrationChangeHistoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：积分变化历史记录控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:33:09
 */
@RestController
@RequestMapping("/member/integration/change/history")
public class IntegrationChangeHistoryController {

    /**
     * 积分变化历史记录接口
     */
    private final IntegrationChangeHistoryService integrationChangeHistoryService;

    @Autowired
    public IntegrationChangeHistoryController(IntegrationChangeHistoryService integrationChangeHistoryService) {
        this.integrationChangeHistoryService = integrationChangeHistoryService;
    }

    /**
     * 功能描述：积分变化历史记录分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页积分变化历史记录
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<IntegrationChangeHistoryVO>> select(HttpServletRequest request, @RequestBody Pagination<IntegrationChangeHistoryVO> pagination) throws Exception {
        return Result.ok(integrationChangeHistoryService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改积分变化历史记录
     *
     * @param request 请求
     * @param dto     积分变化历史记录
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated IntegrationChangeHistoryDTO dto) throws Exception {
        return Result.saveOrUpdate(integrationChangeHistoryService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取积分变化历史记录
     *
     * @param request 请求
     * @param integrationChangeHistoryId  积分变化历史记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<IntegrationChangeHistoryVO> info(HttpServletRequest request, @RequestParam(name = "integrationChangeHistoryId") Long integrationChangeHistoryId) throws Exception {
        return Result.ok(integrationChangeHistoryService.selectById(integrationChangeHistoryId));
    }

    /**
     * 功能描述：删除积分变化历史记录
     *
     * @param request 请求
     * @param integrationChangeHistoryIds 批量删除的积分变化历史记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "integrationChangeHistoryIds") List<Long> integrationChangeHistoryIds) {
        return Result.delete(integrationChangeHistoryService.delete(integrationChangeHistoryIds));
    }

}
